﻿using System;

class ArrayStatistics
{
    public static void Main(string[] args)
    {
        int[] array = { 10, 5, 2, 17, 8, 9, 20, 13 };

        int maxValue = FindMaxValue(array);
        int minValue = FindMinValue(array);
        double averageValue = FindAverageValue(array);
        int sum = CalculateSum(array);

        Console.WriteLine($"最大值: {maxValue}");
        Console.WriteLine($"最小值: {minValue}");
        Console.WriteLine($"平均值: {averageValue}");
        Console.WriteLine($"数组元素和: {sum}");
        Console.Read();

    }

    public static int FindMaxValue(int[] array)
    {
        int max = array[0];
        for (int i = 1; i < array.Length; i++)
        {
            if (array[i] > max)
            {
                max = array[i];
            }
        }
        return max;
    }

    public static int FindMinValue(int[] array)
    {
        int min = array[0];
        for (int i = 1; i < array.Length; i++)
        {
            if (array[i] < min)
            {
                min = array[i];
            }
        }
        return min;
    }

    public static double FindAverageValue(int[] array)
    {
        int sum = CalculateSum(array);
        return (double)sum / array.Length;
    }

    public static int CalculateSum(int[] array)
    {
        int sum = 0;
        for (int i = 0; i < array.Length; i++)
        {
            sum += array[i];
        }
        return sum;
    }
}
